<template>
	<view class="editUser-page">
		<ul>
			<li @click="() => onClickLabel(item)" :class="{'active': handleActive(item) }" v-for="(item,index) in list"
				:key="index">{{item.name}}</li>
		</ul>

		<SSButton title="保存" @click="save" />

	</view>
</template>

<script>
	import SSButton from '@/components/Button.vue'

	export default {
		components: {
			SSButton
		},
		data() {
			return {

				list: [],
				active: [],
				type: null


			};
		},
		computed: {
			handleActive() {
				console.log(this.active)
				return value => this.active.length > 0 && this.active.find(x => x.id == value.id)
			}
		},

		onLoad({ list }) {
			this.active = list && JSON.parse(list) || []
			console.log(this.active)
			this.getTag()

		},
		methods: {
			// 回显
			getData() {
				// this.active = this.active.map(x => this.type == 'user' ? x.tag_id : x.lang_id)
			},
			async getTag() {
				const {
					data
				} = await this.$http.Company.getTag()
				this.list = data
			},
			// 个人技能
			async getUserSkill() {
				const {
					data
				} = await this.$http.Recruit.getUserSkill()
				this.list = data

			},
			// 语言技能
			async getLang() {
				const {
					data
				} = await this.$http.Recruit.getLang()
				this.list = data
			},
			onClickLabel(item) {
				console.log(this.active)
				let hasActive = this.active.find(x => item.id == x.id)
				if (hasActive) {
					let index = this.active.findIndex((x) => item.id == x.id)
					this.active.splice(index, 1)
				} else {
					this.active.push(item)
				}
				console.log(this.active)
			},
			async save() {
				console.log(this.active)
				let pages = getCurrentPages(); //获取所有页面栈实例列表
				let nowPage = pages[pages.length - 1]; //当前页页面实例
				let prevPage = pages[pages.length - 2]; //上一页页面实例
				prevPage.$vm.tagListed = this.active; //修改上一页data里面的地址
				uni.navigateBack({
					delta: 1
				})

				// let apis = this.type == 'user' ? 'usertag' : 'userlang' 
				// const { code, msg } = await this.$http.User[apis](this.active)
				// uni.showToast({
				// 	title: code == 200 ? '保存成功' : msg,
				// 	icon: 'none'
				// })

				// let time = setTimeout(() => {
				// 	clearTimeout(time)
				// 	uni.navigateBack({
				// 		delta: 1
				// 	})
				// }, 1200)
			}
		}

	}
</script>

<style lang="less" scoped>
	.editUser-page {
		ul {
			background: #fff;
			box-shadow: 0px 0px 10px 2px rgba(241, 241, 241, 1);
			border-radius: 8upx;
			margin: 0 32upx;
			margin-top: 10upx;
			margin-bottom: 32upx;
			display: flex;
			flex-wrap: wrap;
			padding: 32upx;

			li {
				color: #2AABE2;
				font-size: 24upx;
				font-weight: 400;
				padding: 0 24upx;
				height: 64upx;
				line-height: 64upx;
				border-radius: 64upx;
				border: 1px solid #2AABE2;
				margin-right: 10upx;
				margin-bottom: 20upx;
			}

			.active {
				color: #fff;
				border: 1px solid #2AABE2;
				background: #2AABE2;

			}

		}


	}
</style>
